/* 728. 自除数 */
/**
 * @param {number} left
 * @param {number} right
 * @return {number[]}
 */
var selfDividingNumbers = function (left, right) {
    const result = []
    while (left <= right) {
        if (left < 10) {
            result.push(left)
        } else {
            const temp = left + ""
            let flag = true
            for (let i = 0; i < temp.length; i++) {
                if (!(+temp[i]) || left % temp[i]) {
                    flag = false
                    break
                }
            }
            if (flag) result.push(left)
        }
        left++
    }
    return result
};
var selfDividingNumbers = function (left, right) {
    const ans = []
    const isSelfDividing = (num) => {
        let temp = num
        while (temp > 0) {
            /* 当前数模10取到该数的最后一位 */
            const digit = temp % 10
            if (digit === 0 || num % digit) return false
            temp = Math.floor(temp / 10)
        }

        return true
    }
    for (let i = left; i <= right; i++) {
        if (isSelfDividing(left)) {
            ans.push(left)
        }
    }
    return ans
}
const result = selfDividingNumbers(47, 85)
console.log('result :>>', result);